Private Sub Command1_Click()
' Store a reference to the document with the name "My Document"
' If the document does not exist, then display an error message.

    Dim appRef As New Photoshop.Application
    Dim docRef As Photoshop.Document
    Dim errorMessage As String
    Dim docName As String
    
    docName = "My Document"
    On Error GoTo DisplayError
        Set docRef = appRef.Documents(docName)
        MsgBox "Document Found!"
    Exit Sub
    
DisplayError:
    errorMessage = "Couldn't locate document " & "'" & docName & "'"
    MsgBox errorMessage
End Sub
